<%@ page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.yaodian100.core.common.utils.ServerValue"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%@ include file="/taglibs.jsp"%>
<link rel="stylesheet" href="<%=ServerValue.getMidContextPath()%>/css/jquery.tooltip.css" />
<script src="<%=ServerValue.getMidContextPath()%>/js/jquery.tooltip.js" type="text/javascript"></script>
<script language="javascript">
	$().ready(function(){
		$("tr[id*='tdDesc_']").tooltip();
	});
	
<yaodian100:checkPermission permissions="OTHER_TUANGOU">
<c-rt:if test="${(product.productType==0 || product.productType==1 || product.productType==7) && product.isDelete=='N'}">
	$().ready(function(){
		$("tr[id*='tdTip_']").tooltip();
		
		$("#loadingImg").dialog({
			bgiframe:true,
			modal:true,
			autoOpen:false
		});
		
		$("#editTuangouDescWindow").dialog({
			title:'编辑团购说明',
			width:450,
			height:220,
			bgiframe:true,
			modal:true,
			autoOpen:false,
			close: function(){
				
			}
		});
		
		$("#queryOrderOperatorWindow").dialog({
			title:'订单操作记录',
			width:450,
			bgiframe:true,
			modal:true,
			autoOpen:false,
			close: function(){
				
			}
		});
		
		$("#saveTuangouDescBtn").click(function(){
			saveTuangouDesc($("#tuangouIdFlg").attr("value"));
		});
	});
	
	function editTuangouDesc(tuangouId){
		$("#tuangouIdFlg").attr("value",tuangouId);
		$("#msgSpan").html("");
		
		var loadingDialog=$("#loadingImg");
		var editTuangouDescWindow=$("#editTuangouDescWindow");
		
		loadingDialog.dialog('open');
		$.post("<%=ServerValue.getMidContextPath()%>/shelf2/editTuangouDesc.do",
			{tuangouId:tuangouId},
			function(mapJson){
				loadingDialog.dialog('close');
				editTuangouDescWindow.dialog('open');
				if(null!=mapJson){
					$("#tuangouDesc").attr("value",mapJson.tuangouDesc);
				}
			},
			"json"
		);
	}
	
	function saveTuangouDesc(tuangouId){
		$("#msgSpan").html("");
		
		var loadingDialog=$("#loadingImg");
		var editTuangouDescWindow=$("#editTuangouDescWindow");
		
		loadingDialog.dialog('open');
		$.post("<%=ServerValue.getMidContextPath()%>/shelf2/saveTuangouDesc.do",
			{tuangouId:tuangouId,tuangouDesc:$("#tuangouDesc").val()},
			function(mapJson){
				loadingDialog.dialog('close');
				editTuangouDescWindow.dialog('open');
				$("#msgSpan").html(mapJson.saveMsg);
			},
			"json"
		);
	}
	
	function queryOrderOperator(tuangouId){
		var loadingDialog=$("#loadingImg");
		var queryOrderOperatorWindow=$("#queryOrderOperatorWindow");
		
		loadingDialog.dialog('open');
		$.post("<%=ServerValue.getMidContextPath()%>/shelf2/queryOrderOperator.do",
			{tuangouId:tuangouId},
			function(mapJson){
				loadingDialog.dialog('close');
				queryOrderOperatorWindow.dialog('open');
				if(null!=mapJson){
					$("#trTag").html("<td>"+mapJson.createUser+"</td><td>"+mapJson.operatorDesc+"</td><td>"+mapJson.createDate+"</td>");
				}else{
					$("#trTag").html("<td colspan='3'>查无资料</td>");
				}
			},
			"json"
		);
	}
</c-rt:if>
</yaodian100:checkPermission>
</script>

<style type="text/css">
    .bg-active {
        background: #D4FAED;
    }
</style>
<h1>商品管理 - 团购商品上下架<br/>
	
</h1>
<div class="f-link">
	<yaodian100:checkPermission permissions="OTHER_TUANGOU">
		<a href="addTuangou.do?productId=${productId}">新增团购卖场</a>
		<a href="listTuangou.do">团购商品列表页</a>
	</yaodian100:checkPermission>
	<a href="<%=ServerValue.getMidContextPath()%>/shelf2/list.do?productId=${productId}">回商品上下架</a>
	<a href="<%=ServerValue.getMidContextPath()%>/product2/list.do">回商品列表页</a>
</div>
<c-rt:if test="${not empty product.productId}">
	<jsp:include page="/WEB-INF/jsp/product/commonMenu2.jsp"/>
</c-rt:if>	
<style type="text/css">
.msg{float:left; line-height:1em; margin:0; display:block;border:1px solid #f66;padding:2px 5px;*padding:2px 5px 1px;}
.msg.rn{background-color:#fff2f2;border-color:#f66;}
</style>
<s:if test="hasActionErrors()">
	<s:actionerror cssClass="msg rn"/>
</s:if>
<s:if test="hasActionMessages()">
	<s:actionmessage cssClass="msg rn"/>
</s:if>
<s:if test="hasFieldErrors()">
	<s:fielderror cssClass="msg rn"/>
</s:if>


<yaodian100:checkPermission permissions="OTHER_TUANGOU">
<c-rt:if test="${(product.productType==0 || product.productType==1 || product.productType==7) && product.isDelete=='N'}">
<br />
<br />
<div class="data-form">
	<s:form action="listTuangou.do" method="post">
		<b>狀態：</b>
		<s:select name="shelfTuangouQueryStatus" list="shelfTuangouQueryStatusMenu.options" listKey="key"  listValue="value.name" />
		<input type="hidden" name="productId" value="${product.productId}" />
		<input type="button" value="搜寻" onclick="this.form.submit();" />
		<font color="red">※有效(已审核、申请中)、无效(下架、审核失败)</font>
	</s:form>
</div>
<br />注：以下蓝色文字为上架中
<s:form action="delShelfTuangou.do" method="post" id="shelfTuangouForm">
	<table class="tb-1" width="100%">
		<thead>
			<tr>
				<th>下架</th>
				<th>上架状态</th>
				<th>促销小标</th>
				<th>活动起始日期时间</th>
				<th>活动结束日期时间</th>
				<th>团购售价</th>
				<th>销售方式</th>
				<th>订购人数</th>
				<th>活动最低订购人数</th>
				<th>限会员购买</th>
				<th>结团状态</th>
				<th>操作</th>
			</tr>
		</thead>
		<tbody>
		<c-rt:forEach items="${tuangouShelfs}" var="tuangouShelf" varStatus="rows_index"> 
			<tr class="${tuangouShelfNow.tuangouId == tuangouShelf.tuangouId ? 'bg-active' : ''}" id="tdTip_${rows_index.count}" title="建立者:${tuangouShelf.createUser} 建立日期:${tuangouShelf.createDate}<br/>修改者:${tuangouShelf.modifyUser} 修改日期:${tuangouShelf.modifyDate}">
			<c-rt:choose>
				<c-rt:when test="${tuangouShelf.status ne 'SHF700'}">
					<td><input name="shelfTuangouDelete" type="checkbox" value="${tuangouShelf.tuangouId}" /></td>
				</c-rt:when>
				<c-rt:otherwise>
					<td></td>
				</c-rt:otherwise>
			</c-rt:choose>
			
				<td>${shelfTuangouStatusMenu.options[tuangouShelf.status].name}</td>
				<td>
					${fn:length(tuangouShelf.promoteName)>20 ? fn:substring(tuangouShelf.promoteName,0,20) : tuangouShelf.promoteName}${fn:length(tuangouShelf.promoteName)>20 ? '...' : ''}
				</td>
				<td><fmt:formatDate value="${tuangouShelf.startDate}" pattern="yyyy-MM-dd HH:mm" /></td>
				<td><fmt:formatDate value="${tuangouShelf.endDate}" pattern="yyyy-MM-dd HH:mm" /></td>
				<td><fmt-rt:formatNumber value="${tuangouShelf.price}" pattern="#####0.0"/></td>
				<td>${tuangouShelf.salesType == '2' ? '抽奖' : '一般'}</td>
				<td>${tuangouShelf.orderQty}</td>
				<td>${tuangouShelf.lowestOrderQty}</td>
				<td>${tuangouShelf.memberLimit == 'Y' ? '是' : '否'}</td>
				<td>${tuangouShelf.tuangouStatus == '0' ? '初始' : tuangouShelf.tuangouStatus == '1' ? '结团' : '流团'}
				</td>
				<td>
				<c-rt:if test="${tuangouShelf.status eq 'SHF000' or tuangouShelf.status eq 'SHF500'}">
					<a href="<%=ServerValue.getMidContextPath()%>/shelf2/editTuangou.do?tuangouId=${tuangouShelf.tuangouId}&productId=${tuangouShelf.productId}">编辑</a><br />
				</c-rt:if>
				<c-rt:if test="${tuangouShelf.status eq 'SHF500'}">
					<a href="javascript:editTuangouDesc(${tuangouShelf.tuangouId});">编辑团购说明</a><br />
				</c-rt:if>
					<a href="javascript:queryOrderOperator(${tuangouShelf.tuangouId});">订单操作记录</a>
				</td>
			</tr> 
		</c-rt:forEach>
		</tbody>
	</table>
	<c-rt:if test="${not empty tuangouShelfs}">
		<br />
		<input type="submit" value="团购活动批次下架"/>
	</c-rt:if>
	<div class="f-link">
		<yaodian100:checkPermission permissions="OTHER_TUANGOU">
		<a href="addTuangou.do?productId=${productId}">新增团购卖场</a>
		<a href="listTuangou.do">团购商品列表页</a>
	</yaodian100:checkPermission>
	<a href="<%=ServerValue.getMidContextPath()%>/shelf2/list.do?productId=${productId}">回商品上下架</a>
	<a href="<%=ServerValue.getMidContextPath()%>/product2/list.do">回商品列表页</a>
	</div>
	<yaodian100:pageutil link="listTuangou.do" pagerObj="${pager}" />
</s:form>

<div id="loadingImg" style="display:none;">
	<img src="/images/loading.gif"/>资料载入中,请稍候...
</div>

<div id="editTuangouDescWindow" style="display:none;">
	<textarea name="tuangouDesc" id="tuangouDesc" cols="80" rows="8"></textarea>
	<input type="hidden" id="tuangouIdFlg" />
	<center>
		<input type="button" id="saveTuangouDescBtn" value="储存" />
		<span id="msgSpan" style="display:inline;color:#FF0000;"></span>
	</center>
</div>

<div id="queryOrderOperatorWindow" style="display:none;">
	<table class="tb-1">
		<thead>
			<tr>
				<th>操作人员</th>
				<th>操作方式</th>
				<th>操作时间</th>
			</tr>
		</thead>
		<tbody><tr id="trTag"></tr></tbody>
	</table>
</div>
</c-rt:if>
</yaodian100:checkPermission>

<br />
<a href="<%=ServerValue.getMidContextPath()%>/image2/edit.do?productId=${product.productId}">< 返回上一步</a>